package org.de.maeyer.statistic;


/**
 * @author Peter De Maeyer
 */
public class LastValueAccumulator implements Accumulator {

	private Object lastValue;

	public LastValueAccumulator(Object lastValue) {
		this.lastValue = lastValue;
	}

	public LastValueAccumulator() {
		reset();
	}
	
	@Override
	public void reset() {
		lastValue = null;
	}
	
	@Override
	public void accumulate() {
	    throw new UnsupportedOperationException();
	}

	@Override
	public void accumulateObject(Object value) {
		this.lastValue = value;
	}
	
	@Override
	public void accumulateLong(long value) {
	    accumulateObject(value);
	}
	
	@Override
	public void accumulateDouble(double value) {
	    accumulateObject(value);
	}
	
	@Override
	public void appendTo(StatisticsBuilder builder) {
	    builder.setLastValue(lastValue);
	}
}
